<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2020/10/19
 * Time: 13:14
 * Features: 权限验证器
 */

namespace app\adminapiv3\validate;


use think\Validate;

class ServerUserGroupValidate extends Validate
{
    //验证规则
    protected $rule = [
        'id' => 'require|integer|egt:1',
        'role|角色' => 'require|max:21|unique:server_user_group',
        'description|角色描述' => 'require|max:42',
        'auth_ids' => 'require|regex:([0-9]+[,]?)+',
        'dataType' => 'in:0,1',
    ];

    //错误信息
    protected $message = [
        'role.unique' => '该角色已存在',
        'auth_ids.require' => '请勾选权限',
        'auth_ids.regex' => '权限参数格式错误'
    ];

    //验证场景
    protected $scene = [
        //添加
        'add' => ['role','description'],
        //修改
        'modify' => ['id','role','description'],
        //授权信息查询
        'auth_query' => ['id','dataType'],
        //授权
        'auth' => ['id','auth_ids'],
    ];


    /**
     * 场景单独验证: 删除
     */
    public function sceneDel()
    {
        //逗号隔开的字符串
        return $this->only(['id'])
            ->remove('id', ['integer','egt'])
            ->append('id','regex:([0-9]+[,]?)+');
    }
}